package com.unnamed.b.atv.sample.holder;

import com.unnamed.b.atv.model.TreeNode;
import com.unnamed.b.atv.sample.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

import java.security.SecureRandom;

/**
 * PlaceHolderHolder
 *
 * @author Administrator
 * @Date 2021/5/26
 */
public class PlaceHolderHolder extends TreeNode.BaseNodeViewHolder<PlaceHolderHolder.PlaceItem> {
    private SecureRandom rand;

    public PlaceHolderHolder(Context context) {
        super(context);
        rand = new SecureRandom();
    }

    @Override
    public Component createNodeView(TreeNode node, PlaceItem value) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_place_node, null, false);
        Text placeName = (Text) component.findComponentById(ResourceTable.Id_place_name);
        placeName.setText(value.name);
        boolean like = rand.nextBoolean();
        Image likeView = (Image) component.findComponentById(ResourceTable.Id_like);
        likeView.setPixelMap(like ? ResourceTable.Media_good_fill : ResourceTable.Media_bad_fill);
        return component;
    }

    @Override
    public void toggle(boolean active) {}

    /**
     * 添加视图显示的内容
     */
    public static class PlaceItem {
        private String name;

        /**
         * 传递参数
         *
         * @param name name
         */
        public PlaceItem(String name) {
            this.name = name;
        }
    }

}
